package com.qingyun.customview.hencode.practice1.views

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.os.Build
import android.util.AttributeSet
import android.view.View

class Practice1DrawRectView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
) : View(context, attrs, defStyleAttr) {
    private val paint = Paint().apply {
        isAntiAlias = true
        style = Paint.Style.STROKE
        color = Color.BLACK
    }
    val outer = RectF(50f, 150f, 200f, 300f)
    val inner = RectF(70f, 170f, 180f, 280f)

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        // 练习内容：使用 canvas.drawRect() 方法画矩形
        canvas.drawRect(50f, 50f, 200f, 100f, paint)
        canvas.drawRoundRect(250f, 50f, 400f, 100f, 20f, 20f, paint)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            canvas.drawDoubleRoundRect(outer, 20f, 20f, inner, 10f, 10f, paint)
        }
    }
}